package com.topvision.controller.glass;

import java.util.List;
import java.util.Map;

import com.topvision.controller.AbstractController;
import com.topvision.model.glass.Sysupload;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.topvision.service.glass.SysuploadService;
import com.topvision.util.PageUtils;
import com.topvision.util.Query;
import com.topvision.util.R;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 文件管理
 *
 * @author jack
 * @email 791127866@qq.com
 * @date 2017-08-09 17:13:45
 */
@RestController
@RequestMapping("glass/sysupload")
public class SysuploadController extends AbstractController {
    @Autowired
    private SysuploadService sysuploadService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("glass/sysupload:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<Sysupload> sysuploadList = sysuploadService.queryList(query);
        int total = sysuploadService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(sysuploadList, total, query.getLimit(), query.getPage());

        return R.success().put("page", pageUtil);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("glass/sysupload:info")
    public R info(@PathVariable("id") Integer id) {
        Sysupload sysupload = sysuploadService.queryObject(id);
        return R.success().put("sysupload", sysupload);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("glass/sysupload:save")
    public R save(@RequestBody Sysupload sysupload) {
        sysuploadService.save(sysupload);
        return R.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("glass/sysupload:update")
    public R update(@RequestBody Sysupload sysupload) {
        sysuploadService.update(sysupload);
        return R.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("glass/sysupload:delete")
    public R delete(@RequestBody Integer[] ids) {
        sysuploadService.deleteBatch(ids);
        return R.success();
    }

    /**
     * 批量下载
     */
    @RequestMapping("/batchDownload")
    @RequiresPermissions("glass/sysupload:batchDownload")
    public R batchDownload(@RequestBody String[] urls, HttpServletResponse response, HttpServletRequest request) {
        // sysuploadService.batchDownload(response, request, urls);
        return R.success();
    }

}
